package com.loan.market.util

import android.content.Context
import android.content.Intent
import android.view.Gravity
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.loan.market.R
import com.loan.market.bean.MotivePromotion
import com.loan.market.ui.LoginActivity
import com.youth.banner.adapter.BannerAdapter

class NoticeAdapter(private val context: Context, data: List<MotivePromotion>?) : BannerAdapter<MotivePromotion, NoticeAdapter.ViewHolder>(data) {

    inner class ViewHolder(val tv: TextView) : RecyclerView.ViewHolder(tv)

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val textView = TextView(parent.context)
        textView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        textView.setLines(1)
        textView.setSingleLine()
        textView.textSize = 12f
        textView.gravity = Gravity.CENTER_VERTICAL
        textView.setTextColor(parent.context.getColor(R.color.color_333))
        return ViewHolder(textView)
    }

    override fun onBindView(holder: ViewHolder, data: MotivePromotion, position: Int, size: Int) {
        holder.tv.text = data.compaignText
        holder.tv.setOnClickListener {
            if (!UserUtil.isLogin()) {
                context.startActivity(Intent(context, LoginActivity::class.java))
                return@setOnClickListener
            }
            context.jump(data.clickTo)
        }
    }

}